
// 调整字段值
export const changeField = function (e, field) {
  if([undefined, null, ''].includes(e)) { e = '' }
  const value = _.isString(e) || _.isNumber(e) || _.isArray(e) || _.isBoolean(e)? e : e.target.value
  // 更新右侧的值
  const item = {...this.item, [field]: value}
  this.$emit('setItem', item)
  // 更新整体表单的值
  let formData = _.searchCover(this.formData, {id: this.item.id}, v => ({...v, [field]: value}))
  formData = formData.map(v => ({...v, children: v.type == 'split' ? _.searchCover(v.children, {id: this.item.id}, v => ({...v, [field]: value})) : v.children}))
  this.$emit('setFormData', formData)
}
// 展开收起
export const toogleSpread = function () {
  if(!this.item.isShowSpread) { return false }
  const isSpread = !this.item.isSpread
  const item = {...this.item, isSpread}
  this.$emit('setItem', item)
  const isCurItem = p => _.safeGet(() => _.difference([p.key, p.key1, p.key2], _.trim(this.item.spreadField, 1).split(',')).length != 3, false)
  const formData = this.formData.map(v => {
    if(v.id == this.item.id) {
      v.isSpread = isSpread
    } else if(v.type == 'split') {
      v.children = v.children.map(k => {
        isCurItem(k) && (k.isShow = isSpread)
        return k
      })
    } else {
      isCurItem(v) && (v.isShow = isSpread)
    }
    return v
  })
  this.$emit('setFormData', formData)
}